﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Description;
using System.ServiceModel.Configuration;

namespace Infrastructure.Services.Behaviors
{
    public class SecurityLogEPBehavior : BehaviorExtensionElement, IEndpointBehavior
    {
        public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
        {
         
        }
        public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
        {
            
        }
        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
        {
            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new SecurityMessageLogInspector());            
        }
        public void Validate(ServiceEndpoint endpoint)
        {
         
        }
        public override Type BehaviorType
        {
            get { return typeof(SecurityLogEPBehavior); }
        }
        protected override object CreateBehavior()
        {
            return new SecurityLogEPBehavior();
        }
    }

    public class SecurityMessageLogInspector : System.ServiceModel.Dispatcher.IDispatchMessageInspector
    {        
        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {
            return null;
        }
        public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            
        }

        
    }
}
